package com.share.lottery.adapter;

import java.util.ArrayList;
import java.util.List;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import com.lidroid.xutils.BitmapUtils;
import com.share.lottery.R;
import com.share.lottery.model.CaiboRmdBean;
import com.share.lottery.model.OrderBean;
import com.share.lottery.model.OrderServiceBean;

/**
 * @author py
 *购买彩宝推荐
 */
public class BuyCaiboAdapter extends BaseAdapter {
	private BitmapUtils bitmapUtils;
	private List<OrderServiceBean> userList = new ArrayList<OrderServiceBean>();
	private  Context context;
	public BuyCaiboAdapter(Context context) {
		this.context = context;
		if (bitmapUtils == null) {
			bitmapUtils = new BitmapUtils(context);
		}
	}
	public int getCount() {

		return userList.size();
	}


	public OrderServiceBean getItem(int arg0) {

		return userList.get(arg0);
	}


	public long getItemId(int arg0) {

		return arg0;
	}


	public View getView(int position, View convertView, ViewGroup arg2) {
		OrderServiceBean caiboRmdBean = userList.get(position);
		ViewHolder viewHolder = null;
		if (convertView == null) {
			convertView = LayoutInflater.from(context).inflate(
					R.layout.item_buyc, null);
			viewHolder = new ViewHolder();
			viewHolder.imgKind = (ImageView) convertView.findViewById(R.id.img_kind);
		
			viewHolder.tvGz = (TextView) convertView.findViewById(R.id.tv_gz);
			viewHolder.tvBuy = (TextView) convertView.findViewById(R.id.tv_buy);
			viewHolder.tvUserName = (TextView) convertView.findViewById(R.id.tv_user_name);
			
			convertView.setTag(viewHolder);
		} else {
			viewHolder = (ViewHolder) convertView.getTag();
		}

		viewHolder.tvGz.setText(caiboRmdBean.getDescription());
		viewHolder.tvUserName.setText(caiboRmdBean.getName());

		bitmapUtils.display(viewHolder.imgKind, caiboRmdBean.getImgPath());


		return convertView;
	}
	class ViewHolder {

		ImageView imgKind;//
		

		TextView tvGz;//请关注

		TextView tvUserName;//用户名
		TextView tvBuy;//购买按钮



	}

	/**
	 * 添加数据
	 * 
	 * @param rows
	 */
	public void addDatas(List<OrderServiceBean> rows) {

		userList.addAll(rows);

		notifyDataSetChanged();
	}

	/**
	 * 清空数据
	 */
	public void clearDatas() {

		userList.clear();
		notifyDataSetChanged();
	}

}
